import java.util.Comparator;
import java.util.Objects;

class Card implements Comparable<Card>{//方法一实现比较的接口
    public int rank; // 数值
    public String suit; // 花色

    public Card(int rank, String suit) {
        this.rank = rank;
        this.suit = suit;
    }

    @Override
    public boolean equals(Object o) {
        if (this==o)return true;
        if (o == null || getClass() != o.getClass()) return false;
        Card card = (Card) o;
        return rank == card.rank && Objects.equals(suit, card.suit);
    }

    @Override
    public int hashCode() {
        return Objects.hash(rank, suit);
    }

    @Override
    public int compareTo(Card o) {
        return this.rank-o.rank;
    }
}
//方法二比较器
class RankComparator implements Comparator<Card> {

    @Override
    public int compare(Card o1, Card o2) {
        return o2.rank-o1.rank;
    }
}
class SuitComparator implements Comparator<Card>{

    @Override
    public int compare(Card o1, Card o2) {
        return o1.suit.compareTo(o2.suit);
    }
}
public class Test2 {
    public static void main(String[] args) {

        RankComparator rankComparator = new RankComparator();
        SuitComparator suitComparator = new SuitComparator();
        Card card=new Card(1, "♠");
        Card card1=new Card(2, "♠");
        System.out.println(suitComparator.compare(card1,card));
       int val =rankComparator.compare(card1,card);
        System.out.println(val);
    }
    public static void main1(String[] args) {
        Card card=new Card(1, "♠");
        Card card1=new Card(2, "♠");
        System.out.println(card.equals(card1));
        System.out.println(card.compareTo(card1));
    }

}